var app = getApp(),
  fetchApi = require("../../../utils/httpPost.js"),
  formatTime = require("../../../component/common.js")
import Toast from '../../../component/vant/toast/toast';
const format = rate => Math.min(Math.max(rate, 0), 100);
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading:true,
    hasData:false,
    netWork:false,
    adoptId:0,
    isiphonex: app.globalData.isiphonex,
    isxiaomi: app.globalData.isxiaomi,
    adopt:{},
    checkboxXieyi:false,
    givens:[],
    signImg:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id){
      this.data.adoptId = parseInt(options.id);
      this.onHttpInit();
    }
  },
  /**
   *  获取领养中心列表
   */
  onHttpInit: function () {
    var that = this;
    fetchApi.httpPost('/farm/poultry/adopt/detail', {
      adopt_id: that.data.adoptId,
    }, function (res) {
      console.log("获取领养详情", res)
      if (res.data.code == 0) {
        that.setData({
          hasData: true,
          adopt: res.data.data.adopt,
          givens: res.data.data.givens,
        })
      }
      that.setData({ netWork: true, isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false, isLoading: false })
    })
  },
  onChangeCheckBox(e){
    console.log('onChangeCheckBox',e)
    this.data.checkboxXieyi = e.detail
    this.setData({
      checkboxXieyi: e.detail
    })
  },
  goShowXieyi(){
  
    wx.navigateTo({
      url: '../poultrySign/index?id=' + this.data.adoptId,
    })
  },
  goSettle(){
    var that = this;
    fetchApi.httpPost('/farm/poultry/order/add', {
      adopt_id: that.data.adoptId,
    }, function (res) {
      console.log("生成领养订单", res)
      if (res.data.code == 0) {
        var orderId = res.data.data;
        wx.navigateTo({
          url: '../poultrySettle/index?id=' + orderId,
        })
      }
      that.setData({ netWork: true, isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false, isLoading: false })
    })
  },
})